<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="elibrary.DaoConnection" %>
<%@ page import="javax.crypto.*" %>
<%@ page language="java" import="java.util.*"%>
<%@ include file="config.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <%

        //the details of the book to be added to the database are fetched from the previous page

        String bookid = request.getParameter("bookid");
        String bookname = request.getParameter("bookname");
        Integer noofcopy = Integer.parseInt(request.getParameter("noofcopy"));
        String author = request.getParameter("author");
        String publisher = request.getParameter("publisher");
        String description = request.getParameter("description");
        String stack = request.getParameter("stack");
        String subject = request.getParameter("subject");
        String category = request.getParameter("category");
        String tags = request.getParameter("tags");


        Statement stmt = null;
        ResultSet results = null;

        // Connect to the database to insert a new book

        try{
	
	
                //connection is made to the database
	
                //the details of the book are inserted into the database
	
                Connection con=DaoConnection.getcon(connectURL, DBuser, DBpass);
                String str ="INSERT INTO BOOK (BOOKID, BOOKNAME, NOOFCOPY, AUTHOR, PUBLISHER, DESCRIPTION, STACK, SUBJECT, CATEGORY, TAGS) VALUES (?,?,?,?,?,?,?,?,?,?)";
                java.sql.PreparedStatement st = con.prepareStatement(str);
                st.setString(1, bookid);
                st.setString(2, bookname);
                st.setInt(3, noofcopy);
                st.setString(4, author);
                st.setString(5, publisher);
                st.setString(6, description);
                st.setString(7, stack);
                st.setString(8, subject);
                st.setString(9, category);
                st.setString(10, tags);
                st.executeUpdate();
                out.println("book added successfully");
	
         }catch(Exception e){
             out.println(e.toString());
             out.println("ERROR!!");
             e.printStackTrace();
         }
        %>

    </body>
</html>